package mian.java.concurrency.thread.volatileDemo;

public class VolatileDemo {

    //public static boolean stop = false;
    //stop使用volatile修饰才能被共享
    public static volatile boolean stop = false;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            int i = 0;
            while (!stop){
                i++;
                System.out.println(i);
            }
        });

        t1.start();

        System.out.println("start");
        Thread.sleep(100);
        stop = true;
    }

}
